/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.santi.framework.common.helper;

import com.santi.framework.common.constants.CommonConstants;
import com.santi.framework.common.vo.KeyValuePair;
import com.santi.framework.dictionary.vo.WordVo;
import com.santi.framework.util.StringUtil;
import com.santi.framework.util.TokenReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Prabhat
 */
public class WordHelper {
    public static WordVo populateWordVo(String[] wordRecord, String langCode){
        WordVo wordVo= null;
       // System.out.println(" Word Record Length"+ wordRecord.length);
         
        if(wordRecord.length >= 6){
            wordVo=new WordVo();
           if(CommonConstants.ENGLISH_LANG_CODE.equalsIgnoreCase(langCode)){
            wordVo.setRootWord(wordRecord[0]);
            wordVo.setPos(wordRecord[1]);
            wordVo.setEnglishSynonym(wordRecord[2]);
            if(!StringUtil.isNullOrBlank(wordRecord[3])){
              wordRecord[3]=wordRecord[3].replace(CommonConstants.thaOld, CommonConstants.thanew); 
                wordVo.setOdiyaMeaning(wordRecord[3]);
            }
            wordVo.setEnglishDescription(wordRecord[4]);
            wordVo.setOdiyaDescription(wordRecord[5]);
           }
           else if(CommonConstants.ODIYA_LANG_CODE.equalsIgnoreCase(langCode)){
            wordVo.setRootWord(wordRecord[1]);
            wordVo.setPos(wordRecord[2]);
            wordVo.setEnglishSynonym(wordRecord[4]);
            wordVo.setOdiyaMeaning(wordRecord[3]);
            //wordVo.setEnglishDescription(wordRecord[4]);
            wordVo.setOdiyaDescription(wordRecord[5]); 
           }
           else if(CommonConstants.HINDI_LANG_CODE.equalsIgnoreCase(langCode)){
            wordVo.setRootWord(wordRecord[1]);
            wordVo.setPos(wordRecord[2]);
            wordVo.setEnglishSynonym(wordRecord[4]);
            wordVo.setOdiyaMeaning(wordRecord[3]);
            //wordVo.setEnglishDescription(wordRecord[4]);
            wordVo.setOdiyaDescription(wordRecord[5]); 
           } 
           else{
               System.out.println(".............Issue in papulating woerds........"+wordRecord.toString());
           }
        }
        
        return wordVo;
    
    }

   public static Map<String,KeyValuePair> populateEngMap(List<String> englishWordLst) {
      
       Map<String,KeyValuePair> wordMap=null;
       if(englishWordLst!=null && englishWordLst.size()>0){
         wordMap = new HashMap<String,KeyValuePair>();
         for(String word:englishWordLst){
             KeyValuePair keyValuePair= new KeyValuePair();
             keyValuePair.setKey(word.trim());
             keyValuePair.setValue(word.trim());
             wordMap.put(word,keyValuePair);
         }
       }
       return wordMap;
       //  throw new UnsupportedOperationException("Not yet implemented");
    }
   public static Map<String,KeyValuePair> populateOdiyaMap(List<String> englishWordLst) {
      
       Map<String,KeyValuePair> wordMap=null;
       if(englishWordLst!=null && englishWordLst.size()>0){
         wordMap = new HashMap<String,KeyValuePair>();
         for(String word:englishWordLst){
             String[] wordsRecord = TokenReader.readTokens(word,CommonConstants.FIELD_SAPARATOR);
             if(wordsRecord.length>=2){
             KeyValuePair keyValuePair= new KeyValuePair();
             //System.out.println("wordsRecord[0]:    "+wordsRecord[0]);
            // System.out.println("wordsRecord[1]:    "+wordsRecord[1]);
//            if(wordsRecord[0].equalsIgnoreCase("baHi")){
//               System.out.println("wordsRecord[0]:    "+wordsRecord[0]);
//              System.out.println("wordsRecord[1]:    "+wordsRecord[1]); 
//            }
             keyValuePair.setKey(wordsRecord[1].trim());
             keyValuePair.setValue(wordsRecord[0].trim());
             wordMap.put(wordsRecord[1].trim(),keyValuePair);
             }
         }
       }
       return wordMap;
       //  throw new UnsupportedOperationException("Not yet implemented");
    }
}
